1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module soup.HSTSPolicy; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import glib.Str; 30 private import glib.c.functions; 31 private import gobject.ObjectG; 32 private import linker.Loader; 33 private import soup.Date; 34 private import soup.Message; 35 private import soup.c.functions; 36 public import soup.c.types; 37 38 39 /** 40 * An HTTP Strict Transport Security policy. 41 * 42 * @domain represents the host that this policy applies to. The domain 43 * must be IDNA-canonicalized. soup_hsts_policy_new() and related methods 44 * will do this for you. 45 * 46 * @max_age contains the 'max-age' value from the Strict Transport 47 * Security header and indicates the time to live of this policy, 48 * in seconds. 49 * 50 * @expires will be non-%NULL if the policy has been set by the host and 51 * hence has an expiry time. If @expires is %NULL, it indicates that the 52 * policy is a permanent session policy set by the user agent. 53 * 54 * If @include_subdomains is %TRUE, the Strict Transport Security policy 55 * must also be enforced on subdomains of @domain. 56 * 57 * Since: 2.68 58 */ 59 public final class HSTSPolicy 60 { 61 /** the main Gtk struct */ 62 protected SoupHSTSPolicy* soupHSTSPolicy; 63 protected bool ownedRef; 64 65 /** Get the main Gtk struct */ 66 public SoupHSTSPolicy* getHSTSPolicyStruct(bool transferOwnership = false) 67 { 68 if (transferOwnership) 69 ownedRef = false; 70 return soupHSTSPolicy; 71 } 72 73 /** the main Gtk struct as a void* */ 74 protected void* getStruct() 75 { 76 return cast(void*)soupHSTSPolicy; 77 } 78 79 /** 80 * Sets our main struct and passes it to the parent class. 81 */ 82 public this (SoupHSTSPolicy* soupHSTSPolicy, bool ownedRef = false) 83 { 84 this.soupHSTSPolicy = soupHSTSPolicy; 85 this.ownedRef = ownedRef; 86 } 87 88 ~this () 89 { 90 if ( Linker.isLoaded(LIBRARY_SOUP[0]) && ownedRef ) 91 soup_hsts_policy_free(soupHSTSPolicy); 92 } 93 94 95 /** 96 * The domain or hostname that the policy applies to 97 */ 98 public @property string domain() 99 { 100 return Str.toString(soupHSTSPolicy.domain); 101 } 102 103 /** Ditto */ 104 public @property void domain(string value) 105 { 106 soupHSTSPolicy.domain = Str.toStringz(value); 107 } 108 109 /** 110 * The maximum age, in seconds, that the policy is valid 111 */ 112 public @property ulong maxAge() 113 { 114 return soupHSTSPolicy.maxAge; 115 } 116 117 /** Ditto */ 118 public @property void maxAge(ulong value) 119 { 120 soupHSTSPolicy.maxAge = value; 121 } 122 123 /** 124 * the policy expiration time, or %NULL for a permanent session policy 125 */ 126 public @property Date expires() 127 { 128 return ObjectG.getDObject!(Date)(soupHSTSPolicy.expires, false); 129 } 130 131 /** Ditto */ 132 public @property void expires(Date value) 133 { 134 soupHSTSPolicy.expires = value.getDateStruct(); 135 } 136 137 /** 138 * %TRUE if the policy applies on subdomains 139 */ 140 public @property bool includeSubdomains() 141 { 142 return soupHSTSPolicy.includeSubdomains != 0; 143 } 144 145 /** Ditto */ 146 public @property void includeSubdomains(bool value) 147 { 148 soupHSTSPolicy.includeSubdomains = value; 149 } 150 151 /** */ 152 public static GType getType() 153 { 154 return soup_hsts_policy_get_type(); 155 } 156 157 /** 158 * Creates a new #SoupHSTSPolicy with the given attributes. 159 * 160 * @domain is a domain on which the strict transport security policy 161 * represented by this object must be enforced. 162 * 163 * @max_age is used to set the "expires" attribute on the policy; pass 164 * SOUP_HSTS_POLICY_MAX_AGE_PAST for an already-expired policy, or a 165 * lifetime in seconds. 166 * 167 * If @include_subdomains is %TRUE, the strict transport security policy 168 * must also be enforced on all subdomains of @domain. 169 * 170 * Params: 171 * domain = policy domain or hostname 172 * maxAge = max age of the policy 173 * includeSubdomains = %TRUE if the policy applies on subdomains 174 * 175 * Returns: a new #SoupHSTSPolicy. 176 * 177 * Since: 2.68 178 * 179 * Throws: ConstructionException GTK+ fails to create the object. 180 */ 181 public this(string domain, ulong maxAge, bool includeSubdomains) 182 { 183 auto __p = soup_hsts_policy_new(Str.toStringz(domain), maxAge, includeSubdomains); 184 185 if(__p is null) 186 { 187 throw new ConstructionException("null returned by new"); 188 } 189 190 this(cast(SoupHSTSPolicy*) __p); 191 } 192 193 /** 194 * Parses @msg's first "Strict-Transport-Security" response header and 195 * returns a #SoupHSTSPolicy. 196 * 197 * Params: 198 * msg = a #SoupMessage 199 * 200 * Returns: a new #SoupHSTSPolicy, or %NULL if no valid 201 * "Strict-Transport-Security" response header was found. 202 * 203 * Since: 2.68 204 * 205 * Throws: ConstructionException GTK+ fails to create the object. 206 */ 207 public this(Message msg) 208 { 209 auto __p = soup_hsts_policy_new_from_response((msg is null) ? null : msg.getMessageStruct()); 210 211 if(__p is null) 212 { 213 throw new ConstructionException("null returned by new_from_response"); 214 } 215 216 this(cast(SoupHSTSPolicy*) __p); 217 } 218 219 /** 220 * Full version of #soup_hsts_policy_new(), to use with an existing 221 * expiration date. See #soup_hsts_policy_new() for details. 222 * 223 * Params: 224 * domain = policy domain or hostname 225 * maxAge = max age of the policy 226 * expires = the date of expiration of the policy or %NULL for a permanent policy 227 * includeSubdomains = %TRUE if the policy applies on subdomains 228 * 229 * Returns: a new #SoupHSTSPolicy. 230 * 231 * Since: 2.68 232 * 233 * Throws: ConstructionException GTK+ fails to create the object. 234 */ 235 public this(string domain, ulong maxAge, Date expires, bool includeSubdomains) 236 { 237 auto __p = soup_hsts_policy_new_full(Str.toStringz(domain), maxAge, (expires is null) ? null : expires.getDateStruct(), includeSubdomains); 238 239 if(__p is null) 240 { 241 throw new ConstructionException("null returned by new_full"); 242 } 243 244 this(cast(SoupHSTSPolicy*) __p); 245 } 246 247 /** 248 * Creates a new session #SoupHSTSPolicy with the given attributes. 249 * A session policy is a policy that is valid during the lifetime of 250 * the #SoupHSTSEnforcer it is added to. Contrary to regular policies, 251 * it has no expiration date and is not stored in persistent 252 * enforcers. These policies are useful for user-agent to load their 253 * own or user-defined rules. 254 * 255 * @domain is a domain on which the strict transport security policy 256 * represented by this object must be enforced. 257 * 258 * If @include_subdomains is %TRUE, the strict transport security policy 259 * must also be enforced on all subdomains of @domain. 260 * 261 * Params: 262 * domain = policy domain or hostname 263 * includeSubdomains = %TRUE if the policy applies on sub domains 264 * 265 * Returns: a new #SoupHSTSPolicy. 266 * 267 * Since: 2.68 268 * 269 * Throws: ConstructionException GTK+ fails to create the object. 270 */ 271 public this(string domain, bool includeSubdomains) 272 { 273 auto __p = soup_hsts_policy_new_session_policy(Str.toStringz(domain), includeSubdomains); 274 275 if(__p is null) 276 { 277 throw new ConstructionException("null returned by new_session_policy"); 278 } 279 280 this(cast(SoupHSTSPolicy*) __p); 281 } 282 283 /** 284 * Copies @policy. 285 * 286 * Returns: a copy of @policy 287 * 288 * Since: 2.68 289 */ 290 public HSTSPolicy copy() 291 { 292 auto __p = soup_hsts_policy_copy(soupHSTSPolicy); 293 294 if(__p is null) 295 { 296 return null; 297 } 298 299 return ObjectG.getDObject!(HSTSPolicy)(cast(SoupHSTSPolicy*) __p, true); 300 } 301 302 /** 303 * Tests if @policy1 and @policy2 are equal. 304 * 305 * Params: 306 * policy2 = a #SoupHSTSPolicy 307 * 308 * Returns: whether the policies are equal. 309 * 310 * Since: 2.68 311 */ 312 public bool equal(HSTSPolicy policy2) 313 { 314 return soup_hsts_policy_equal(soupHSTSPolicy, (policy2 is null) ? null : policy2.getHSTSPolicyStruct()) != 0; 315 } 316 317 /** 318 * Frees @policy. 319 * 320 * Since: 2.68 321 */ 322 public void free() 323 { 324 soup_hsts_policy_free(soupHSTSPolicy); 325 ownedRef = false; 326 } 327 328 /** 329 * Gets @policy's domain. 330 * 331 * Returns: @policy's domain. 332 * 333 * Since: 2.68 334 */ 335 public string getDomain() 336 { 337 return Str.toString(soup_hsts_policy_get_domain(soupHSTSPolicy)); 338 } 339 340 /** 341 * Gets whether @policy include its subdomains. 342 * 343 * Returns: %TRUE if @policy includes subdomains, %FALSE otherwise. 344 * 345 * Since: 2.68 346 */ 347 public bool includesSubdomains() 348 { 349 return soup_hsts_policy_includes_subdomains(soupHSTSPolicy) != 0; 350 } 351 352 /** 353 * Gets whether @policy is expired. Permanent policies never 354 * expire. 355 * 356 * Returns: %TRUE if @policy is expired, %FALSE otherwise. 357 * 358 * Since: 2.68 359 */ 360 public bool isExpired() 361 { 362 return soup_hsts_policy_is_expired(soupHSTSPolicy) != 0; 363 } 364 365 /** 366 * Gets whether @policy is a non-permanent, non-expirable session policy. 367 * see soup_hsts_policy_new_session_policy() for details. 368 * 369 * Returns: %TRUE if @policy is permanent, %FALSE otherwise 370 * 371 * Since: 2.68 372 */ 373 public bool isSessionPolicy() 374 { 375 return soup_hsts_policy_is_session_policy(soupHSTSPolicy) != 0; 376 } 377 }